/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 * Origin source from MaNGOS(GPL2).
 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
 */
#include "MapManager.h"
#include "World.h"

namespace PQServiceCore
{
	MapManager::MapManager()
		: _gridCleanUpDelay(SWorld.getConfig(CONFIG_UINT32_INTERVAL_GRIDCLEAN))
	{
	}

	void MapManager::setGridCleanUpDelay(uint32 time)
   {
		if( time < MIN_GRID_DELAY ){
            _gridCleanUpDelay = MIN_GRID_DELAY;
		} else{
            _gridCleanUpDelay = time;
		}
    }

	void MapManager::setMapUpdateInterval(uint32 time)
    {
		if( time > MIN_MAP_UPDATE_DELAY ){
            time = MIN_MAP_UPDATE_DELAY;
		}

		_timer.SetInterval(time);
        _timer.Reset();
    }

	void MapManager::Update(unsigned int deltaT)
	{
		_timer.Update(deltaT);
		if(_timer.Passed()){
			return;
		}

		for(UnorderedMap::iterator iter=_maps.begin(); iter != _maps.end(); ++iter){
			iter->second->Update((uint32)_timer.GetCurrent());
		}
		
		for (TransportSet::iterator iter = _transports.begin(); iter != _transports.end(); ++iter){
			(*iter)->Update((uint32)_timer.GetCurrent());
		}

		_timer.SetCurrent(0);

	}


}
